package pe.gob.mpfn.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.validator.LengthValidator;
import org.primefaces.component.autocomplete.AutoComplete;
import org.primefaces.component.calendar.Calendar;
import org.primefaces.component.inputtext.InputText;
import org.primefaces.component.inputtextarea.InputTextarea;
import org.primefaces.component.message.Message;
import org.primefaces.context.RequestContext;
import org.primefaces.event.CloseEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.roo.addon.jsf.managedbean.RooJsfManagedBean;
import org.springframework.roo.addon.serializable.RooSerializable;
import pe.gob.mpfn.controller.converter.ExpedienteConverter;
import pe.gob.mpfn.controller.converter.PersonalConverter;
import pe.gob.mpfn.model.Expediente;
import pe.gob.mpfn.model.Informe;
import pe.gob.mpfn.model.Personal;
import pe.gob.mpfn.service.ExpedienteService;
import pe.gob.mpfn.service.InformeService;
import pe.gob.mpfn.service.PersonalService;

@Configurable
@ManagedBean(name = "informeBean")
@SessionScoped
@RooSerializable
@RooJsfManagedBean(entity = Informe.class, beanName = "informeBean")
public class InformeBean implements Serializable  {

	@Autowired
    InformeService informeService;

	@Autowired
    PersonalService personalService;

	@Autowired
    ExpedienteService expedienteService;

	private String name = "Informes";

	private Informe informe;

	private List<Informe> allInformes;

	private boolean dataVisible = false;

	private List<String> columns;

	private HtmlPanelGrid createPanelGrid;

	private HtmlPanelGrid editPanelGrid;

	private HtmlPanelGrid viewPanelGrid;

	private boolean createDialogVisible = false;

	@PostConstruct
    public void init() {
        columns = new ArrayList<String>();
        columns.add("strNumeroInforme");
        columns.add("strConclusiones");
        columns.add("datFechaRegistro");
        columns.add("chrEstado");
        columns.add("txtInformePdf");
    }

	public String getName() {
        return name;
    }

	public List<String> getColumns() {
        return columns;
    }

	public List<Informe> getAllInformes() {
        return allInformes;
    }

	public void setAllInformes(List<Informe> allInformes) {
        this.allInformes = allInformes;
    }

	public String findAllInformes() {
        allInformes = informeService.findAllInformes();
        dataVisible = !allInformes.isEmpty();
        return null;
    }

	public boolean isDataVisible() {
        return dataVisible;
    }

	public void setDataVisible(boolean dataVisible) {
        this.dataVisible = dataVisible;
    }

	public HtmlPanelGrid getCreatePanelGrid() {
        if (createPanelGrid == null) {
            createPanelGrid = populateCreatePanel();
        }
        return createPanelGrid;
    }

	public void setCreatePanelGrid(HtmlPanelGrid createPanelGrid) {
        this.createPanelGrid = createPanelGrid;
    }

	public HtmlPanelGrid getEditPanelGrid() {
        if (editPanelGrid == null) {
            editPanelGrid = populateEditPanel();
        }
        return editPanelGrid;
    }

	public void setEditPanelGrid(HtmlPanelGrid editPanelGrid) {
        this.editPanelGrid = editPanelGrid;
    }

	public HtmlPanelGrid getViewPanelGrid() {
        if (viewPanelGrid == null) {
            viewPanelGrid = populateViewPanel();
        }
        return viewPanelGrid;
    }

	public void setViewPanelGrid(HtmlPanelGrid viewPanelGrid) {
        this.viewPanelGrid = viewPanelGrid;
    }

	public HtmlPanelGrid populateCreatePanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText intResponsableIdCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        intResponsableIdCreateOutput.setId("intResponsableIdCreateOutput");
        intResponsableIdCreateOutput.setValue("Int Responsable Id:   ");
        htmlPanelGrid.getChildren().add(intResponsableIdCreateOutput);
        
        AutoComplete intResponsableIdCreateInput = (AutoComplete) application.createComponent(AutoComplete.COMPONENT_TYPE);
        intResponsableIdCreateInput.setId("intResponsableIdCreateInput");
        intResponsableIdCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.intResponsableId}", Personal.class));
        intResponsableIdCreateInput.setCompleteMethod(expressionFactory.createMethodExpression(elContext, "#{informeBean.completeIntResponsableId}", List.class, new Class[] { String.class }));
        intResponsableIdCreateInput.setDropdown(true);
        intResponsableIdCreateInput.setValueExpression("var", expressionFactory.createValueExpression(elContext, "intResponsableId", String.class));
        intResponsableIdCreateInput.setValueExpression("itemLabel", expressionFactory.createValueExpression(elContext, "#{intResponsableId.strNombre} #{intResponsableId.strApellidoPaterno} #{intResponsableId.strApellidoMaterno} #{intResponsableId.strUsuario}", String.class));
        intResponsableIdCreateInput.setValueExpression("itemValue", expressionFactory.createValueExpression(elContext, "#{intResponsableId}", Personal.class));
        intResponsableIdCreateInput.setConverter(new PersonalConverter());
        intResponsableIdCreateInput.setRequired(false);
        htmlPanelGrid.getChildren().add(intResponsableIdCreateInput);
        
        Message intResponsableIdCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        intResponsableIdCreateInputMessage.setId("intResponsableIdCreateInputMessage");
        intResponsableIdCreateInputMessage.setFor("intResponsableIdCreateInput");
        intResponsableIdCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(intResponsableIdCreateInputMessage);
        
        HtmlOutputText strNumeroExpedienteIdCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strNumeroExpedienteIdCreateOutput.setId("strNumeroExpedienteIdCreateOutput");
        strNumeroExpedienteIdCreateOutput.setValue("Str Numero Expediente Id:   ");
        htmlPanelGrid.getChildren().add(strNumeroExpedienteIdCreateOutput);
        
        AutoComplete strNumeroExpedienteIdCreateInput = (AutoComplete) application.createComponent(AutoComplete.COMPONENT_TYPE);
        strNumeroExpedienteIdCreateInput.setId("strNumeroExpedienteIdCreateInput");
        strNumeroExpedienteIdCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strNumeroExpedienteId}", Expediente.class));
        strNumeroExpedienteIdCreateInput.setCompleteMethod(expressionFactory.createMethodExpression(elContext, "#{informeBean.completeStrNumeroExpedienteId}", List.class, new Class[] { String.class }));
        strNumeroExpedienteIdCreateInput.setDropdown(true);
        strNumeroExpedienteIdCreateInput.setValueExpression("var", expressionFactory.createValueExpression(elContext, "strNumeroExpedienteId", String.class));
        strNumeroExpedienteIdCreateInput.setValueExpression("itemLabel", expressionFactory.createValueExpression(elContext, "#{strNumeroExpedienteId.strLugarSuceso} #{strNumeroExpedienteId.datFechaRegistro} #{strNumeroExpedienteId.datFechaSuceso} #{strNumeroExpedienteId.strNumeroExpedienteId}", String.class));
        strNumeroExpedienteIdCreateInput.setValueExpression("itemValue", expressionFactory.createValueExpression(elContext, "#{strNumeroExpedienteId}", Expediente.class));
        strNumeroExpedienteIdCreateInput.setConverter(new ExpedienteConverter());
        strNumeroExpedienteIdCreateInput.setRequired(false);
        htmlPanelGrid.getChildren().add(strNumeroExpedienteIdCreateInput);
        
        Message strNumeroExpedienteIdCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strNumeroExpedienteIdCreateInputMessage.setId("strNumeroExpedienteIdCreateInputMessage");
        strNumeroExpedienteIdCreateInputMessage.setFor("strNumeroExpedienteIdCreateInput");
        strNumeroExpedienteIdCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strNumeroExpedienteIdCreateInputMessage);
        
        HtmlOutputText strNumeroInformeCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strNumeroInformeCreateOutput.setId("strNumeroInformeCreateOutput");
        strNumeroInformeCreateOutput.setValue("Str Numero Informe: * ");
        htmlPanelGrid.getChildren().add(strNumeroInformeCreateOutput);
        
        InputText strNumeroInformeCreateInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        strNumeroInformeCreateInput.setId("strNumeroInformeCreateInput");
        strNumeroInformeCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strNumeroInforme}", String.class));
        LengthValidator strNumeroInformeCreateInputValidator = new LengthValidator();
        strNumeroInformeCreateInputValidator.setMaximum(12);
        strNumeroInformeCreateInput.addValidator(strNumeroInformeCreateInputValidator);
        strNumeroInformeCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strNumeroInformeCreateInput);
        
        Message strNumeroInformeCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strNumeroInformeCreateInputMessage.setId("strNumeroInformeCreateInputMessage");
        strNumeroInformeCreateInputMessage.setFor("strNumeroInformeCreateInput");
        strNumeroInformeCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strNumeroInformeCreateInputMessage);
        
        HtmlOutputText strConclusionesCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strConclusionesCreateOutput.setId("strConclusionesCreateOutput");
        strConclusionesCreateOutput.setValue("Str Conclusiones: * ");
        htmlPanelGrid.getChildren().add(strConclusionesCreateOutput);
        
        InputTextarea strConclusionesCreateInput = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strConclusionesCreateInput.setId("strConclusionesCreateInput");
        strConclusionesCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strConclusiones}", String.class));
        LengthValidator strConclusionesCreateInputValidator = new LengthValidator();
        strConclusionesCreateInputValidator.setMaximum(200);
        strConclusionesCreateInput.addValidator(strConclusionesCreateInputValidator);
        strConclusionesCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strConclusionesCreateInput);
        
        Message strConclusionesCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strConclusionesCreateInputMessage.setId("strConclusionesCreateInputMessage");
        strConclusionesCreateInputMessage.setFor("strConclusionesCreateInput");
        strConclusionesCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strConclusionesCreateInputMessage);
        
        HtmlOutputText datFechaRegistroCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        datFechaRegistroCreateOutput.setId("datFechaRegistroCreateOutput");
        datFechaRegistroCreateOutput.setValue("Dat Fecha Registro: * ");
        htmlPanelGrid.getChildren().add(datFechaRegistroCreateOutput);
        
        Calendar datFechaRegistroCreateInput = (Calendar) application.createComponent(Calendar.COMPONENT_TYPE);
        datFechaRegistroCreateInput.setId("datFechaRegistroCreateInput");
        datFechaRegistroCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.datFechaRegistro}", Date.class));
        datFechaRegistroCreateInput.setNavigator(true);
        datFechaRegistroCreateInput.setEffect("slideDown");
        datFechaRegistroCreateInput.setPattern("dd/MM/yyyy");
        datFechaRegistroCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(datFechaRegistroCreateInput);
        
        Message datFechaRegistroCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        datFechaRegistroCreateInputMessage.setId("datFechaRegistroCreateInputMessage");
        datFechaRegistroCreateInputMessage.setFor("datFechaRegistroCreateInput");
        datFechaRegistroCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(datFechaRegistroCreateInputMessage);
        
        HtmlOutputText chrEstadoCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoCreateOutput.setId("chrEstadoCreateOutput");
        chrEstadoCreateOutput.setValue("Chr Estado: * ");
        htmlPanelGrid.getChildren().add(chrEstadoCreateOutput);
        
        InputText chrEstadoCreateInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        chrEstadoCreateInput.setId("chrEstadoCreateInput");
        chrEstadoCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.chrEstado}", Character.class));
        chrEstadoCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(chrEstadoCreateInput);
        
        Message chrEstadoCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        chrEstadoCreateInputMessage.setId("chrEstadoCreateInputMessage");
        chrEstadoCreateInputMessage.setFor("chrEstadoCreateInput");
        chrEstadoCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(chrEstadoCreateInputMessage);
        
        HtmlOutputText txtInformePdfCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        txtInformePdfCreateOutput.setId("txtInformePdfCreateOutput");
        txtInformePdfCreateOutput.setValue("Txt Informe Pdf:   ");
        htmlPanelGrid.getChildren().add(txtInformePdfCreateOutput);
        
        InputText txtInformePdfCreateInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        txtInformePdfCreateInput.setId("txtInformePdfCreateInput");
        txtInformePdfCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.txtInformePdf}", String.class));
        htmlPanelGrid.getChildren().add(txtInformePdfCreateInput);
        
        Message txtInformePdfCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        txtInformePdfCreateInputMessage.setId("txtInformePdfCreateInputMessage");
        txtInformePdfCreateInputMessage.setFor("txtInformePdfCreateInput");
        txtInformePdfCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(txtInformePdfCreateInputMessage);
        
        return htmlPanelGrid;
    }

	public HtmlPanelGrid populateEditPanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText intResponsableIdEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        intResponsableIdEditOutput.setId("intResponsableIdEditOutput");
        intResponsableIdEditOutput.setValue("Int Responsable Id:   ");
        htmlPanelGrid.getChildren().add(intResponsableIdEditOutput);
        
        AutoComplete intResponsableIdEditInput = (AutoComplete) application.createComponent(AutoComplete.COMPONENT_TYPE);
        intResponsableIdEditInput.setId("intResponsableIdEditInput");
        intResponsableIdEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.intResponsableId}", Personal.class));
        intResponsableIdEditInput.setCompleteMethod(expressionFactory.createMethodExpression(elContext, "#{informeBean.completeIntResponsableId}", List.class, new Class[] { String.class }));
        intResponsableIdEditInput.setDropdown(true);
        intResponsableIdEditInput.setValueExpression("var", expressionFactory.createValueExpression(elContext, "intResponsableId", String.class));
        intResponsableIdEditInput.setValueExpression("itemLabel", expressionFactory.createValueExpression(elContext, "#{intResponsableId.strNombre} #{intResponsableId.strApellidoPaterno} #{intResponsableId.strApellidoMaterno} #{intResponsableId.strUsuario}", String.class));
        intResponsableIdEditInput.setValueExpression("itemValue", expressionFactory.createValueExpression(elContext, "#{intResponsableId}", Personal.class));
        intResponsableIdEditInput.setConverter(new PersonalConverter());
        intResponsableIdEditInput.setRequired(false);
        htmlPanelGrid.getChildren().add(intResponsableIdEditInput);
        
        Message intResponsableIdEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        intResponsableIdEditInputMessage.setId("intResponsableIdEditInputMessage");
        intResponsableIdEditInputMessage.setFor("intResponsableIdEditInput");
        intResponsableIdEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(intResponsableIdEditInputMessage);
        
        HtmlOutputText strNumeroExpedienteIdEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strNumeroExpedienteIdEditOutput.setId("strNumeroExpedienteIdEditOutput");
        strNumeroExpedienteIdEditOutput.setValue("Str Numero Expediente Id:   ");
        htmlPanelGrid.getChildren().add(strNumeroExpedienteIdEditOutput);
        
        AutoComplete strNumeroExpedienteIdEditInput = (AutoComplete) application.createComponent(AutoComplete.COMPONENT_TYPE);
        strNumeroExpedienteIdEditInput.setId("strNumeroExpedienteIdEditInput");
        strNumeroExpedienteIdEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strNumeroExpedienteId}", Expediente.class));
        strNumeroExpedienteIdEditInput.setCompleteMethod(expressionFactory.createMethodExpression(elContext, "#{informeBean.completeStrNumeroExpedienteId}", List.class, new Class[] { String.class }));
        strNumeroExpedienteIdEditInput.setDropdown(true);
        strNumeroExpedienteIdEditInput.setValueExpression("var", expressionFactory.createValueExpression(elContext, "strNumeroExpedienteId", String.class));
        strNumeroExpedienteIdEditInput.setValueExpression("itemLabel", expressionFactory.createValueExpression(elContext, "#{strNumeroExpedienteId.strLugarSuceso} #{strNumeroExpedienteId.datFechaRegistro} #{strNumeroExpedienteId.datFechaSuceso} #{strNumeroExpedienteId.strNumeroExpedienteId}", String.class));
        strNumeroExpedienteIdEditInput.setValueExpression("itemValue", expressionFactory.createValueExpression(elContext, "#{strNumeroExpedienteId}", Expediente.class));
        strNumeroExpedienteIdEditInput.setConverter(new ExpedienteConverter());
        strNumeroExpedienteIdEditInput.setRequired(false);
        htmlPanelGrid.getChildren().add(strNumeroExpedienteIdEditInput);
        
        Message strNumeroExpedienteIdEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strNumeroExpedienteIdEditInputMessage.setId("strNumeroExpedienteIdEditInputMessage");
        strNumeroExpedienteIdEditInputMessage.setFor("strNumeroExpedienteIdEditInput");
        strNumeroExpedienteIdEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strNumeroExpedienteIdEditInputMessage);
        
        HtmlOutputText strNumeroInformeEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strNumeroInformeEditOutput.setId("strNumeroInformeEditOutput");
        strNumeroInformeEditOutput.setValue("Str Numero Informe: * ");
        htmlPanelGrid.getChildren().add(strNumeroInformeEditOutput);
        
        InputText strNumeroInformeEditInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        strNumeroInformeEditInput.setId("strNumeroInformeEditInput");
        strNumeroInformeEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strNumeroInforme}", String.class));
        LengthValidator strNumeroInformeEditInputValidator = new LengthValidator();
        strNumeroInformeEditInputValidator.setMaximum(12);
        strNumeroInformeEditInput.addValidator(strNumeroInformeEditInputValidator);
        strNumeroInformeEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strNumeroInformeEditInput);
        
        Message strNumeroInformeEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strNumeroInformeEditInputMessage.setId("strNumeroInformeEditInputMessage");
        strNumeroInformeEditInputMessage.setFor("strNumeroInformeEditInput");
        strNumeroInformeEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strNumeroInformeEditInputMessage);
        
        HtmlOutputText strConclusionesEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strConclusionesEditOutput.setId("strConclusionesEditOutput");
        strConclusionesEditOutput.setValue("Str Conclusiones: * ");
        htmlPanelGrid.getChildren().add(strConclusionesEditOutput);
        
        InputTextarea strConclusionesEditInput = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strConclusionesEditInput.setId("strConclusionesEditInput");
        strConclusionesEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strConclusiones}", String.class));
        LengthValidator strConclusionesEditInputValidator = new LengthValidator();
        strConclusionesEditInputValidator.setMaximum(200);
        strConclusionesEditInput.addValidator(strConclusionesEditInputValidator);
        strConclusionesEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strConclusionesEditInput);
        
        Message strConclusionesEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strConclusionesEditInputMessage.setId("strConclusionesEditInputMessage");
        strConclusionesEditInputMessage.setFor("strConclusionesEditInput");
        strConclusionesEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strConclusionesEditInputMessage);
        
        HtmlOutputText datFechaRegistroEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        datFechaRegistroEditOutput.setId("datFechaRegistroEditOutput");
        datFechaRegistroEditOutput.setValue("Dat Fecha Registro: * ");
        htmlPanelGrid.getChildren().add(datFechaRegistroEditOutput);
        
        Calendar datFechaRegistroEditInput = (Calendar) application.createComponent(Calendar.COMPONENT_TYPE);
        datFechaRegistroEditInput.setId("datFechaRegistroEditInput");
        datFechaRegistroEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.datFechaRegistro}", Date.class));
        datFechaRegistroEditInput.setNavigator(true);
        datFechaRegistroEditInput.setEffect("slideDown");
        datFechaRegistroEditInput.setPattern("dd/MM/yyyy");
        datFechaRegistroEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(datFechaRegistroEditInput);
        
        Message datFechaRegistroEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        datFechaRegistroEditInputMessage.setId("datFechaRegistroEditInputMessage");
        datFechaRegistroEditInputMessage.setFor("datFechaRegistroEditInput");
        datFechaRegistroEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(datFechaRegistroEditInputMessage);
        
        HtmlOutputText chrEstadoEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoEditOutput.setId("chrEstadoEditOutput");
        chrEstadoEditOutput.setValue("Chr Estado: * ");
        htmlPanelGrid.getChildren().add(chrEstadoEditOutput);
        
        InputText chrEstadoEditInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        chrEstadoEditInput.setId("chrEstadoEditInput");
        chrEstadoEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.chrEstado}", Character.class));
        chrEstadoEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(chrEstadoEditInput);
        
        Message chrEstadoEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        chrEstadoEditInputMessage.setId("chrEstadoEditInputMessage");
        chrEstadoEditInputMessage.setFor("chrEstadoEditInput");
        chrEstadoEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(chrEstadoEditInputMessage);
        
        HtmlOutputText txtInformePdfEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        txtInformePdfEditOutput.setId("txtInformePdfEditOutput");
        txtInformePdfEditOutput.setValue("Txt Informe Pdf:   ");
        htmlPanelGrid.getChildren().add(txtInformePdfEditOutput);
        
        InputText txtInformePdfEditInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        txtInformePdfEditInput.setId("txtInformePdfEditInput");
        txtInformePdfEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.txtInformePdf}", String.class));
        htmlPanelGrid.getChildren().add(txtInformePdfEditInput);
        
        Message txtInformePdfEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        txtInformePdfEditInputMessage.setId("txtInformePdfEditInputMessage");
        txtInformePdfEditInputMessage.setFor("txtInformePdfEditInput");
        txtInformePdfEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(txtInformePdfEditInputMessage);
        
        return htmlPanelGrid;
    }

	public HtmlPanelGrid populateViewPanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText intResponsableIdLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        intResponsableIdLabel.setId("intResponsableIdLabel");
        intResponsableIdLabel.setValue("Int Responsable Id:   ");
        htmlPanelGrid.getChildren().add(intResponsableIdLabel);
        
        HtmlOutputText intResponsableIdValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        intResponsableIdValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.intResponsableId}", Personal.class));
        intResponsableIdValue.setConverter(new PersonalConverter());
        htmlPanelGrid.getChildren().add(intResponsableIdValue);
        
        HtmlOutputText strNumeroExpedienteIdLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strNumeroExpedienteIdLabel.setId("strNumeroExpedienteIdLabel");
        strNumeroExpedienteIdLabel.setValue("Str Numero Expediente Id:   ");
        htmlPanelGrid.getChildren().add(strNumeroExpedienteIdLabel);
        
        HtmlOutputText strNumeroExpedienteIdValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strNumeroExpedienteIdValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strNumeroExpedienteId}", Expediente.class));
        strNumeroExpedienteIdValue.setConverter(new ExpedienteConverter());
        htmlPanelGrid.getChildren().add(strNumeroExpedienteIdValue);
        
        HtmlOutputText strNumeroInformeLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strNumeroInformeLabel.setId("strNumeroInformeLabel");
        strNumeroInformeLabel.setValue("Str Numero Informe:   ");
        htmlPanelGrid.getChildren().add(strNumeroInformeLabel);
        
        HtmlOutputText strNumeroInformeValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strNumeroInformeValue.setId("strNumeroInformeValue");
        strNumeroInformeValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strNumeroInforme}", String.class));
        htmlPanelGrid.getChildren().add(strNumeroInformeValue);
        
        HtmlOutputText strConclusionesLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strConclusionesLabel.setId("strConclusionesLabel");
        strConclusionesLabel.setValue("Str Conclusiones:   ");
        htmlPanelGrid.getChildren().add(strConclusionesLabel);
        
        InputTextarea strConclusionesValue = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strConclusionesValue.setId("strConclusionesValue");
        strConclusionesValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.strConclusiones}", String.class));
        strConclusionesValue.setReadonly(true);
        strConclusionesValue.setDisabled(true);
        htmlPanelGrid.getChildren().add(strConclusionesValue);
        
        HtmlOutputText datFechaRegistroLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        datFechaRegistroLabel.setId("datFechaRegistroLabel");
        datFechaRegistroLabel.setValue("Dat Fecha Registro:   ");
        htmlPanelGrid.getChildren().add(datFechaRegistroLabel);
        
        HtmlOutputText datFechaRegistroValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        datFechaRegistroValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.datFechaRegistro}", Date.class));
        DateTimeConverter datFechaRegistroValueConverter = (DateTimeConverter) application.createConverter(DateTimeConverter.CONVERTER_ID);
        datFechaRegistroValueConverter.setPattern("dd/MM/yyyy");
        datFechaRegistroValue.setConverter(datFechaRegistroValueConverter);
        htmlPanelGrid.getChildren().add(datFechaRegistroValue);
        
        HtmlOutputText chrEstadoLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoLabel.setId("chrEstadoLabel");
        chrEstadoLabel.setValue("Chr Estado:   ");
        htmlPanelGrid.getChildren().add(chrEstadoLabel);
        
        HtmlOutputText chrEstadoValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.chrEstado}", String.class));
        htmlPanelGrid.getChildren().add(chrEstadoValue);
        
        HtmlOutputText txtInformePdfLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        txtInformePdfLabel.setId("txtInformePdfLabel");
        txtInformePdfLabel.setValue("Txt Informe Pdf:   ");
        htmlPanelGrid.getChildren().add(txtInformePdfLabel);
        
        HtmlOutputText txtInformePdfValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        txtInformePdfValue.setId("txtInformePdfValue");
        txtInformePdfValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{informeBean.informe.txtInformePdf}", String.class));
        htmlPanelGrid.getChildren().add(txtInformePdfValue);
        
        return htmlPanelGrid;
    }

	public Informe getInforme() {
        if (informe == null) {
            informe = new Informe();
        }
        return informe;
    }

	public void setInforme(Informe informe) {
        this.informe = informe;
    }

	public List<Personal> completeIntResponsableId(String query) {
        List<Personal> suggestions = new ArrayList<Personal>();
        for (Personal personal : personalService.findAllPersonals()) {
            String personalStr = String.valueOf(personal.getStrNombre() +  " "  + personal.getStrApellidoPaterno() +  " "  + personal.getStrApellidoMaterno() +  " "  + personal.getStrUsuario());
            if (personalStr.toLowerCase().startsWith(query.toLowerCase())) {
                suggestions.add(personal);
            }
        }
        return suggestions;
    }

	public List<Expediente> completeStrNumeroExpedienteId(String query) {
        List<Expediente> suggestions = new ArrayList<Expediente>();
        for (Expediente expediente : expedienteService.findAllExpedientes()) {
            String expedienteStr = String.valueOf(expediente.getStrLugarSuceso() +  " "  + expediente.getDatFechaRegistro() +  " "  + expediente.getDatFechaSuceso() +  " "  + expediente.getStrNumeroExpedienteId());
            if (expedienteStr.toLowerCase().startsWith(query.toLowerCase())) {
                suggestions.add(expediente);
            }
        }
        return suggestions;
    }

	public String onEdit() {
        return null;
    }

	public boolean isCreateDialogVisible() {
        return createDialogVisible;
    }

	public void setCreateDialogVisible(boolean createDialogVisible) {
        this.createDialogVisible = createDialogVisible;
    }

	public String displayList() {
        createDialogVisible = false;
        findAllInformes();
        return "informe";
    }

	public String displayCreateDialog() {
        informe = new Informe();
        createDialogVisible = true;
        return "informe";
    }

	public String persist() {
        String message = "";
        if (informe.getIntInformeId() != null) {
            informeService.updateInforme(informe);
            message = "Successfully updated";
        } else {
            informeService.saveInforme(informe);
            message = "Successfully created";
        }
        RequestContext context = RequestContext.getCurrentInstance();
        context.execute("createDialog.hide()");
        context.execute("editDialog.hide()");
        
        FacesMessage facesMessage = new FacesMessage(message);
        FacesContext.getCurrentInstance().addMessage(null, facesMessage);
        reset();
        return findAllInformes();
    }

	public String delete() {
        informeService.deleteInforme(informe);
        FacesMessage facesMessage = new FacesMessage("Successfully deleted");
        FacesContext.getCurrentInstance().addMessage(null, facesMessage);
        reset();
        return findAllInformes();
    }

	public void reset() {
        informe = null;
        createDialogVisible = false;
    }

	public void handleDialogClose(CloseEvent event) {
        reset();
    }

	private static final long serialVersionUID = 1L;
}
